import { defineStore } from "pinia";
import localforage from "localforage";

const useUIStore = defineStore({
  id: "ui",
  state: () => ({ layoutMode: "horizontal" }), //'horizontal' | 'vertical'
  actions: {
    async toggle() {
      if (this.layoutMode == "horizontal") {
        this.layoutMode = "vertical";
      } else {
        this.layoutMode = "horizontal";
      }
      await localforage.setItem("ui-layoutMode", this.layoutMode); // 保存数据
    },
    async fetch() {
      const value = (await localforage.getItem("ui-layoutMode")) as string; // 加载数据
      this.layoutMode = value || "horizontal"; // 更新存储值
    }
  }
});
export default useUIStore;
